package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/***
 * 对应教材 P163-P171 增加了返回页面
 */
@Controller
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 使用@DateTimeFormat注解绑定日期数据
     */
    @RequestMapping("/getBirthday2")
    public String getBirthday(@DateTimeFormat(
            pattern = "yyyy-MM-dd") Date birthday) {
        System.out.println("birthday=" + birthday);
        return "success";
    }
    @RequestMapping("/loginUser")
    public String loginUser(User user,HttpServletRequest request){
       System.out.println(user);
        System.out.println(userService.isLucky(user));
         String url;
         request.getSession().setAttribute("user",user);
        if (userService.isLucky(user))
            url = "input2";
        else
            url="info";
        return url;
    }


}

